package com.ny.zmb.openapi.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ny.zmb.openapi.entity.PmUser;
import com.ny.zmb.openapi.mapper.PmUserMapper;
import com.ny.zmb.openapi.service.IPmUserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 * 会员表 服务实现类
 * </p>
 *
 * @author xie
 * @since 2024-10-25
 */
@Service
public class UserPmUserServiceImpl extends ServiceImpl<PmUserMapper, PmUser> implements IPmUserService {
    @Resource
    private PmUserMapper userMapper;
    public String getAllPid(PmUser pmUser){

        StringBuffer pidArr = new StringBuffer();
        while (pmUser != null) {
            pmUser = getPmUserByPid(pmUser);
            if (pmUser != null) {
                pidArr.append(pmUser.getId());
            }
        }
        return pidArr.toString();
    }

    @Override
    public PmUser getByUserId(Integer userId) {
        QueryWrapper<PmUser> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id", userId);
        return userMapper.selectOne(queryWrapper);
    }

    public PmUser getPmUserByPid(PmUser pmUser) {
        if (pmUser.getPid() == null || pmUser.getPid() == 0) {
            return null;
        }
        return userMapper.selectById(pmUser.getPid());
    }
}
